package cn.bellychang.stack.bobo.linkedstack01addandremovefirst;

import cn.bellychang.iiterface.bobo.Stack;

/**
 * @author: bellychang
 * @date: 2020/2/10
 */
public class LinkedStack<E> implements Stack<E> {

    private LinkedList<E> list;

    public LinkedStack() {
        this.list = new LinkedList<>();
    }

    @Override
    public int size() {
        return list.getSize();
    }

    @Override
    public boolean isEmpty() {
        return list.isEmpty();
    }

    @Override
    public void push(E e) {
        list.addFirst(e);
    }

    @Override
    public E pop() {
        return list.removeFirst();
    }

    @Override
    public E peek() {
        return list.getFirst();
    }

    @Override
    public String toString() {
        return "LinkedStack Top{" + list + '}';
    }
}
